package com.haixee.parkdemo.auth.controller;

import com.haixee.parkdemo.auth.model.Tenant;
import com.haixee.parkdemo.auth.service.TenantService;
import com.haixee.parkdemo.common.response.ResResult;
import com.haixee.parkdemo.common.response.ResUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/tenant")
public class TenantController {

    @Autowired
    private TenantService tenantService;

    @PostMapping
    public ResResult addTenant(@RequestBody Tenant tenant) {

        tenantService.addTenant(tenant.getName());
        return ResUtil.success();
    }

    @PostMapping("/update")
    public ResResult updateTenant(@RequestBody Tenant tenant) {

        tenantService.updateTenant(tenant.getId(), tenant.getName());
        return ResUtil.success();
    }

    @GetMapping
    public ResResult getAll() {
        return ResUtil.success(tenantService.selectAll());
    }
}
